﻿using System;
using System.Collections.Specialized;
using ScrappyDB.Membership;
using NUnit.Framework;
using System.Web.Security;

namespace ScrappyDB.IntegrationTests.Membership
{
    /// <summary>
    ///This is a test class for SdbMembershipProviderTest and is intended
    ///to contain all SdbMembershipProviderTest Unit Tests
    ///</summary>
    [TestFixture]
    public class SdbMembershipProviderTest
    {
        private TestContext testContextInstance;

        private SdbMembershipProvider _provider;

        string username = "test";
        string username2 = "test2";
        string password = "password";
        string email = "ScrappyDB.IntegrationTests@scrappydog.com";
        string passwordQuestion = "Test Question";
        string passwordAnswer = "Test Answer";
        bool isApproved = false;
        object providerUserKey = Guid.Empty;
        object providerUserKey2 = Guid.NewGuid();


        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        [TestFixtureSetUp]
        public  void Init()
        {
        }

        private void InitializeProvider()
        {
            _provider = new SdbMembershipProvider();
            var config = new NameValueCollection
                             {
                                 {"applicationName", "ScrappyDB.IntegrationTests"},
                                 {"enablePasswordRetrieval", "false"},
                                 {"enablePasswordReset", "true"},
                                 {"requiresQuestionAndAnswer", "true"},
                                 {"requiresUniqueEmail", "false"},
                                 {"passwordFormat", "Clear"},
                                 {"maxInvalidPasswordAttempts", "5"},
                                 {"minRequiredPasswordLength", "7"},
                                 {"minRequiredNonalphanumericCharacters", "1"},
                                 {"passwordAttemptWindow", "10"}
                             };

            _provider.Initialize(config["name"], config);
        }

        [SetUp]
        public void MyTestInitialize()
        {

            InitializeProvider();
            _provider.DeleteUser(username, false);
            _provider.DeleteUser(username2, false);
        }

        //Use TestCleanup to run code after each test has run
        //[TearDown]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ValidateUser
        ///</summary>
        [Test, Ignore]
        public void ValidateUserTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            string password = string.Empty; 
            bool expected = false; 
            bool actual;
            actual = target.ValidateUser(username, password);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for UpdateUser
        ///</summary>
        [Test, Ignore]
        public void UpdateUserTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            MembershipUser user = null; 
            target.UpdateUser(user);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }


        /// <summary>
        ///A test for UnlockUser
        ///</summary>
        [Test, Ignore]
        public void UnlockUserTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            bool expected = false; 
            bool actual;
            actual = target.UnlockUser(username);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }


        /// <summary>
        ///A test for ResetPassword
        ///</summary>
        [Test, Ignore]
        public void ResetPasswordTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            string answer = string.Empty; 
            string expected = string.Empty; 
            string actual;
            actual = target.ResetPassword(username, answer);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetUserNameByEmail
        ///</summary>
        [Test, Ignore]
        public void GetUserNameByEmailTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string email = string.Empty; 
            string expected = string.Empty; 
            string actual;
            actual = target.GetUserNameByEmail(email);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetUser
        ///</summary>
        [Test, Ignore]
        public void GetUserTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            bool userIsOnline = false; 
            MembershipUser expected = null; 
            MembershipUser actual;
            actual = target.GetUser(username, userIsOnline);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetPassword
        ///</summary>
        [Test, Ignore]
        public void GetPasswordTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            string answer = string.Empty; 
            string expected = string.Empty; 
            string actual;
            actual = target.GetPassword(username, answer);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for GetNumberOfUsersOnline
        ///</summary>
        [Test, Ignore]
        public void GetNumberOfUsersOnlineTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            int expected = 0; 
            int actual;
            actual = target.GetNumberOfUsersOnline();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }



        /// <summary>
        ///A test for ChangePassword
        ///</summary>
        [Test, Ignore]
        public void ChangePasswordTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            string oldPwd = string.Empty; 
            string newPwd = string.Empty; 
            bool expected = false; 
            bool actual;
            actual = target.ChangePassword(username, oldPwd, newPwd);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ChangePasswordQuestionAndAnswer
        ///</summary>
        [Test, Ignore]
        public void ChangePasswordQuestionAndAnswerTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string username = string.Empty; 
            string password = string.Empty; 
            string newPwdQuestion = string.Empty; 
            string newPwdAnswer = string.Empty; 
            bool expected = false; 
            bool actual;
            actual = target.ChangePasswordQuestionAndAnswer(username, password, newPwdQuestion, newPwdAnswer);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for FindUsersByName
        ///</summary>
        [Test, Ignore]
        public void FindUsersByNameTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string usernameToMatch = string.Empty; 
            int pageIndex = 0; 
            int pageSize = 0; 
            int totalRecords = 0; 
            int totalRecordsExpected = 0; 
            MembershipUserCollection expected = null; 
            MembershipUserCollection actual;
            actual = target.FindUsersByName(usernameToMatch, pageIndex, pageSize, out totalRecords);
            Assert.AreEqual(totalRecordsExpected, totalRecords);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for FindUsersByEmail
        ///</summary>
        [Test, Ignore]
        public void FindUsersByEmailTest()
        {
            SdbMembershipProvider target = new SdbMembershipProvider(); 
            string emailToMatch = string.Empty; 
            int pageIndex = 0; 
            int pageSize = 0; 
            int totalRecords = 0; 
            int totalRecordsExpected = 0; 
            MembershipUserCollection expected = null; 
            MembershipUserCollection actual;
            actual = target.FindUsersByEmail(emailToMatch, pageIndex, pageSize, out totalRecords);
            Assert.AreEqual(totalRecordsExpected, totalRecords);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for DeleteUser
        ///</summary>
        [Test, Ignore]
        public void DeleteUserTest()
        {
           //DeleteUser is tested by every other test is in this class so lets just call it good for now...
            Assert.IsTrue(true);
        }

        /// <summary>
        ///A test for CreateUser
        ///</summary>
        [Test]
        public void CreateUserTest()
        {
            MembershipCreateStatus statusActual;
            MembershipUser actual = _provider.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out statusActual);

            Assert.AreEqual(MembershipCreateStatus.Success, statusActual);
        }

        /// <summary>
        ///A test for GetAllUsers
        ///</summary>
        [Test]
        public void GetAllUsersTest()
        {
            MembershipCreateStatus status;
            MembershipUser user1 = _provider.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
            MembershipUser user2 = _provider.CreateUser(username2, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey2, out status);

            int totalRecords;
            MembershipUserCollection actual = _provider.GetAllUsers(0, 100, out totalRecords);

            Assert.AreEqual(2, totalRecords);
            Assert.AreEqual(2, actual.Count);
        }
    }
}
